home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / uwpc201.zip / UW-SRC.ZIP / MOUSE.CPP < prev    next >
C/C++ Source or Header  |  1991-06-09  |  5KB  |  168 lines

  1. //-------------------------------------------------------------------------
  2. //
  3. // MOUSE.CPP - Declarations for handling the mouse events.
  4. // 
  5. //  This file is part of UW/PC - a multi-window comms package for the PC.
  6. //  Copyright (C) 1990-1991  Rhys Weatherley
  7. //
  8. //  This program is free software; you can redistribute it and/or modify
  9. //  it under the terms of the GNU General Public License as published by
  10. //  the Free Software Foundation; either version 1, or (at your option)
  11. //  any later version.
  12. //
  13. //  This program is distributed in the hope that it will be useful,
  14. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. //  GNU General Public License for more details.
  17. //
  18. //  You should have received a copy of the GNU General Public License
  19. //  along with this program; if not, write to the Free Software
  20. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. //
  22. // Revision History:
  23. // ================
  24. //
  25. //  Version  DD/MM/YY  By  Description
  26. //  -------  --------  --  --------------------------------------
  27. //    1.0    08/06/91  RW  Original Version of MOUSE.CPP
  28. //
  29. // You may contact the author by:
  30. // =============================
  31. //
  32. //  e-mail: rhys@cs.uq.oz.au
  33. //    mail: Rhys Weatherley
  34. //          5 Horizon Drive
  35. //          Jamboree Heights
  36. //          Queensland 4074
  37. //        Australia
  38. //
  39. //-------------------------------------------------------------------------
  40.  
  41. #pragma    inline            // Module contains inline assembly.
  42.  
  43. #include "mouse.h"        // Declarations for this module.
  44. #include "client.h"        // Client declarations.
  45. #include "screen.h"        // Screen accessing declarations.
  46. #include <dos.h>        // Interrupt services, etc.
  47.  
  48. //
  49. // The following variable will be non-zero when the mouse status
  50. // has been detectably changed.
  51. //
  52. int    MouseChange=0;
  53.  
  54. //
  55. // The following variable will be non-zero when the mouse is active.
  56. //
  57. int    MouseActive=0;
  58.  
  59. //
  60. // Global data for this module.
  61. //
  62. static    void    far *SaveIntSubr;
  63. static    int    SaveIntMask;
  64. static    int    MouseVisible;
  65.  
  66. //
  67. // Define the mouse interrupt subroutine to be called
  68. // whenever the mouse status changes.
  69. ///
  70. static    void    far MouseIntSubr (void)
  71. {
  72.   asm push ds;
  73.   asm mov ax,DGROUP;        // Restore the proper data segment address.
  74.   asm mov ds,ax;
  75.   MouseChange = 1;        // Record a change in the mouse status.
  76.   asm pop ds;            // Restore DS and exit to mouse driver.
  77. } // MouseIntSubr //
  78.  
  79. //
  80. // Initialise the mouse to be used by UW/PC.  This routine should
  81. // be called after the screen has been initialised.  It returns
  82. // a non-zero value if the mouse could be initialised, zero otherwise.
  83. //
  84. int    InitMouse (void)
  85. {
  86.   REGS regs;
  87.   SREGS sregs;
  88.   MouseChange = 0;
  89.   MouseVisible = 0;
  90.   regs.x.ax = 0x0000;        // Reset the mouse driver.
  91.   int86 (0x33,®s,®s);
  92.   if (regs.x.ax != 0xFFFF)
  93.     return (0);            // Could not initialise the driver.
  94.   regs.x.ax = 0x0014;        // Install mouse interrupt subroutine.
  95.   regs.x.cx = 0x001F;        // Call for mouse movements and buttons.
  96.   regs.x.dx = FP_OFF (MouseIntSubr);
  97.   sregs.es = FP_SEG (MouseIntSubr);
  98.   int86x (0x33,®s,®s,&sregs);
  99.   SaveIntSubr = MK_FP (sregs.es,regs.x.dx);
  100.   SaveIntMask = regs.x.cx;
  101.   MouseActive = 1;
  102.   regs.x.ax = 0x0004;        // Set the initial mouse cursor position.
  103.   regs.x.cx = (HardwareScreen.width - 1) * 8;
  104.   regs.x.dx = (HardwareScreen.height - 1) * 8;
  105.   int86 (0x33,®s,®s);
  106.   ShowMouse ();
  107.   return (1);
  108. } // InitMouse //
  109.  
  110. //
  111. // Terminate the handling of the mouse.
  112. //
  113. void    TermMouse (void)
  114. {
  115.   REGS regs;
  116.   SREGS sregs;
  117.   HideMouse ();
  118.   regs.x.ax = 0x0014;        // Restore mouse interrupt subroutine.
  119.   regs.x.cx = SaveIntMask;
  120.   regs.x.dx = FP_OFF (SaveIntSubr);
  121.   sregs.es = FP_SEG (SaveIntSubr);
  122.   int86x (0x33,®s,®s,&sregs);
  123.   MouseChange = 0;
  124.   MouseActive = 0;
  125. } // TermMouse //
  126.  
  127. //
  128. // Send the current mouse status to the given client.  This may
  129. // be called any time after initialisation, but usually after
  130. // "MouseChange" has been set.
  131. //
  132. void    SendMouseEvent (UWClient *client)
  133. {
  134.   REGS regs;
  135.   regs.x.ax = 0x0003;        // Read the mouse status.
  136.   int86 (0x33,®s,®s);
  137.   client -> mouse (regs.x.cx / 8,regs.x.dx / 8,(regs.x.bx & 3));
  138.   MouseChange = 0;
  139. } // SendMouseEvent //
  140.  
  141. //
  142. // Display the mouse if it is not already visible.
  143. //
  144. void    ShowMouse (void)
  145. {
  146.   REGS regs;
  147.   if (MouseActive && !MouseVisible)
  148.     {
  149.       regs.x.ax = 0x0001;
  150.       int86 (0x33,®s,®s);
  151.       MouseVisible = 1;
  152.     }
  153. } // ShowMouse //
  154.  
  155. //
  156. // Remove the mouse from the screen.
  157. //
  158. void    HideMouse (void)
  159. {
  160.   REGS regs;
  161.   if (MouseActive && MouseVisible)
  162.     {
  163.       regs.x.ax = 0x0002;
  164.       int86 (0x33,®s,®s);
  165.       MouseVisible = 0;
  166.     }
  167. } // HideMouse //
  168.